package org.example.memberlist_back.server;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.memberlist_back.common.Res;
import org.example.memberlist_back.entity.Member;
import org.example.memberlist_back.mapper.MemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServerImpl  extends ServiceImpl<MemberMapper, Member> implements  LoginServer{
    @Autowired
    private MemberMapper memberMapper;
    public Res<Member> login(String username, String password) {
        Member member = null;
        member=memberMapper.selectUserByUsername(username);
        int code = 400;
        String msg = "";
        if(member!=null){
            if(member.getPassword().equals(password)){
                code = 200;
                msg = "登录成功";
            }else{
                msg = "密码错误";
                member=null;
            }
        }else{
            msg = "用户不存在";
        }
        return new Res<Member>(code,msg,member);
    }
}
